package com.lk.labsystem.controller;

import com.lk.labsystem.pojo.Lab;
import com.lk.labsystem.service.LabService;
import com.lk.labsystem.utils.ResultOBJ;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/adminapi/labs")
public class LabController {
    @Autowired
    LabService labService;

    @GetMapping
    public List<Lab> getLabList(Lab lab) {
        return labService.getLabList(lab);
    }

//    添加实验室
    @PostMapping
    public ResultOBJ addLabList(@RequestBody Lab lab) {
        try {
            labService.addLabList(lab);
            return ResultOBJ.ADD_SUCCESS;
        } catch (Exception e) {
            return ResultOBJ.ADD_ERROR;
        }
    }

//    更新实验室信息
    @PutMapping(value="/{id}")
    public ResultOBJ updateLabList(@PathVariable Integer id,@RequestBody Lab lab){
        try {
            lab.setId(id);
            labService.updateLabList(lab);
            return ResultOBJ.UPDATE_SUCCESS;
        } catch (Exception e) {
//            throw new RuntimeException(e);
            return ResultOBJ.UPDATE_ERROR;
        }
    }

    //删除权限
    @DeleteMapping(value = "/{id}")
    public ResultOBJ deleteLabList(@PathVariable Integer id){
        try {
            labService.deleteLabList(id);
            return ResultOBJ.DELETE_SUCCESS;
        } catch (Exception e) {
            return ResultOBJ.DELETE_ERROR;
        }
    }

}
